package wml.switcher;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class ConnectActivity extends Activity {
	private EditText txtIp;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.connect);
		MyApplication.getInstance().addActivity(this);
		Button btnConnect = (Button) this.findViewById(R.id.btnConnect);
		Button btnExit = (Button) this.findViewById(R.id.btnExit);
		txtIp = (EditText)this.findViewById(R.id.ip);
		btnConnect.setOnClickListener(new OnConnectListener());
		btnExit.setOnClickListener(new OnExitListener());
		
	}
	
	class OnConnectListener implements OnClickListener{
		@Override
		public void onClick(View v) {
			if(txtIp.getText().toString().trim().length()<1)
				return;
			Intent intent = new Intent(ConnectActivity.this,
					ViewSwitcherActivity.class);// 为Intent设置要激活的组件
			Bundle bundle = new Bundle();
			bundle.putString("ip", txtIp.getText().toString());
			intent.putExtras(bundle);
			startActivityForResult(intent, -1);// 第二个参数为设置的请求码
		}
	}
	
	class OnExitListener implements OnClickListener{
		@Override
		public void onClick(View v) {

			MyApplication.getInstance().exit();
		}
	}
}
